class Solution
{
public:
    bool doesValidArrayExist(vector<int> &derived)
    {
        int n = derived.size();
        vector<int> origin(n);
        origin[0] = 1;
        for (int i = 1; i < n; ++i)
        {
            origin[i] = derived[i - 1] ^ origin[i - 1];
        }
        if (origin[0] == derived[n - 1] ^ origin[n - 1])
        {
            return true;
        }
        origin[0] = 0;
        for (int i = 1; i < n; ++i)
        {
            origin[i] = derived[i - 1] ^ origin[i - 1];
        }
        if (origin[0] == derived[n - 1] ^ origin[n - 1])
        {
            return true;
        }
        return false;
    }
};